package com.hsy.sunflowerbao.home.ui

import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.flux.ui.adapter.FActivityRecycleAdapter
import com.flux.utils.GlideUtil
import com.hsy.sunflowerbao.R
import com.hsy.sunflowerbao.base.ui.adapter.BaseHolder
import com.hsy.sunflowerbao.home.data.CouponData
import kotlinx.android.synthetic.main.item_coupon.view.*
import java.lang.ref.WeakReference

/**
 * Created on 2018/4/4.
 *
 * @author Yang
 */
class CouponAdapter(activity: DetailActivity, var items: List<CouponData>) : FActivityRecycleAdapter<DetailActivity>(WeakReference(activity)) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = BaseHolder(getItemView(R.layout.item_coupon, parent))

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        GlideUtil.load(items[position].img, holder.itemView.couponImage, R.drawable.default_class, activity = mActivity.get())
        holder.itemView.couponName.text = items[position].name
        holder.itemView.couponDescription.text = items[position].brief
        holder.itemView.couponType.text = items[position].tags
        holder.itemView.couponUse.setOnClickListener { _ -> mActivity.get()?.checkCoupon(items[position].id, position) }
    }

    override fun getItemCount() = items.size
}